var CurrentUser;    //Global variable 
function getName(){
var user = JSON.parse(localStorage.getItem("loggedinUser"));
CurrentUser = user; //Added to set current user in global var 

if (user) {
    console.log("Currently logged in: " + user["name"]);
    document.getElementById("name-goes-here").innerText = user["name"];
} else {
    console.log("No one is logged in");
  }
}
getName();

function populateHistory() { 
// find out who is logged in 
//var loggedinUser = JSON.parse(localStorage.getItem("loggedinUser")); //person who is 
//logged in
var users = JSON.parse(localStorage.getItem("users")); //the whole users database
let email =CurrentUser["email"];
const user = users.find(u => u.email === email); 
 
if (user) { 

    historyArray = user["history"]; 
    historyArray.forEach((hist) => { 
        // Get references to the HTML card and div to hold the history 
        let historyCardTemplate = document.getElementById("simple-history-card"); 
        let historyCardGroup = document.getElementById("history-goes-here"); 
        let onecard = historyCardTemplate.content.cloneNode(true);

        d = hist.date; 
onecard.querySelector(".info").innerHTML = d; 
historyCardGroup.appendChild(onecard);
         
    }) 
     
} else { 
    console.log("No user found with email"+email); 
} 

} 
populateHistory(); 